package com.ly.system.controller;

import com.common.core.domain.AjaxResult;
import com.common.core.web.controller.BaseController;
import com.common.fileupload.domain.FileModel;
import com.common.fileupload.upload.S3FileUploader;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@Api(value = "文件上传")
@RequiredArgsConstructor
public class SysFileUploadController extends BaseController {


    private final S3FileUploader<?> s3FileUploader;


    @PostMapping(value = "/upload")
    @ApiOperation(value = "文件上传",notes = "李勇")
    public AjaxResult upload(@ApiParam(value = "文件", required = true) MultipartFile file,
                             @ApiParam(value = "桶文件夹名", required = true) String prefix){
        FileModel fileModel = s3FileUploader.upload(file, prefix);
        return AjaxResult.success().put("fileModel",fileModel);
    }


    @GetMapping(value = "/peek")
    @ApiOperation(value = "获得文件信息",notes = "李勇")
    public AjaxResult peek(@ApiParam(value = "文件路径", required = true) String filePath){
        return AjaxResult.success().put("fileInfo",s3FileUploader.peek(filePath));
    }



}
